import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Confirm from 'vux/src/components/confirm/index.vue'
import util from '@/common/util.js'

export default {
  name: 'pointto',
  components: {Confirm},
  data () {
    return {
      siteId: '',
      studentId: '',
      // 今日点到
      content: [],
      // 点到统计
      list: [],
      show: false,
      pageNo: 1
    }
  },
  mounted () {
    var _this = this
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    if (_this.studentId == '-1') {
      _this.show = true
    } else {
      http.post(CONSTANT.STUDENTSIGNTODAY, {
        orgId: _this.siteId,
        userId: _this.studentId
      }, (res) => {
        if (res.data.todaySignList.length > 0) {
          _this.content = res.data.todaySignList
        }
      })
      this.studSignIn()
    }
  },
  methods: {
    studSignIn () {
      var _this = this
      http.post(CONSTANT.SIGNTERM, {
        orgId: _this.siteId,
        userId: _this.studentId,
        pageNo: _this.pageNo
      }, (res) => {
        let data = res.data
        console.log('classList', data.rows)
        if (data.rows != null && data.rows.length > 0) {
          if (_this.pageNo === 1) {
            _this.list = data.rows
          } else if (_this.pageNo > 1) {
            _this.list = _this.list.concat(data.rows)
          }
        } else {
          if (_this.pageNo > 1) {
            alert('没有更多了！')
            _this.pageNo--
            return
          } else {
            _this.list = []
          }
        }
      })
    },
    onCancel () {
      // 取消按钮
    },
    onConfirm () {
    //  确定按钮
      var _this = this
      _this.$router.push({path: '/login'})
    },
    lookmore () {
      var _this = this
      if (_this.pageNo >= 1) {
        _this.pageNo++
        this.studSignIn()
      }
    },
    goPointtoDetails (id) {
      var _this = this
      window.sessionStorage.setItem('classId', id)
      _this.$router.push({path: '/pointtoList'})
    },
    dateFormat (date) {
      return util.dateFormat(date, true)
    }
  }
}
